package com.liqi.sms.utils;

import java.math.BigDecimal;
import java.util.Calendar;

/**
 * 中智中台签名加密工具类
 */
public class AuthenticationUtils {

    /**
     * 获取当前时间时间戳字符 毫秒
     * @return
     */
    public static String getCurrentTimestamp(){
        return new BigDecimal(Calendar.getInstance().getTimeInMillis()).toString();
    }

    /**
     * SM3加密
     * @param appkey 应用唯一标识
     * @param timestamp 请求时间戳
     * @param requestid 请求的唯一标识号
     * @param usertoken 用户鉴权令牌
     * @param securityKey 应用令牌
     * @return
     */
    public static String sign(String appkey, String timestamp, String requestid,String usertoken,String securityKey) {
        //格式化字符  appkey + timestamp + requestid + usertoken + securitykey
        String signResult = String.format("%s%s%s%s%s", appkey, timestamp,requestid,usertoken,securityKey);
        System.out.println("SM3加密原始字符：" + signResult);
        //SM3加密转大写
        String sign = Sm3Util.digest(signResult).toUpperCase();
        System.out.println("SM3加密后字符：" + sign);
        return sign;
    }

}
